package member.dao;

import java.sql.SQLException;
import java.util.List;

import member.dto.MemberDto;
import util.SqlMapLocator;

public class MemberDao {
	private static MemberDao instance = null;

	private MemberDao() {
	}

	public static MemberDao getInstance() {
		if (instance != null)
			instance = new MemberDao();
		return instance;

	}

	public static List selectAll() throws SQLException {
		return SqlMapLocator.getSqlMap().queryForList("member.selectAll");
	}

	public static MemberDto selectId(String id) throws SQLException {
		return (MemberDto) SqlMapLocator.getSqlMap().queryForObject(
				"member.selectId", id);
	}

	public static int confirmId(String id) throws SQLException {
		int check = 0;
		MemberDto confirmId = (MemberDto) SqlMapLocator.getSqlMap()
				.queryForObject("member.confirmId", id);

		if (confirmId == null)
			check = 0;

		if (confirmId != null)
			check = 1;
		return check;
	}

	public static void insertUser(MemberDto paramClass) throws SQLException {
		SqlMapLocator.getSqlMap().insert("member.insertUser", paramClass);
	}

	public static int userCheck(String id, String password) throws SQLException {
		int check = -1;
		String dbPassword = (String) SqlMapLocator.getSqlMap().queryForObject(
				"member.userCheck", id);

		if (dbPassword != null) {
			if (dbPassword.equals(password))
				check = 1;
			else
				check = 0;
		} else
			check = -1;

		return check;
	}

	public static MemberDto userAllData(String id) throws SQLException {
		return (MemberDto) SqlMapLocator.getSqlMap().queryForObject(
				"member.userAllData", id);
	}

	public static void updateUser(MemberDto paramClass) throws SQLException {
		SqlMapLocator.getSqlMap().update("member.updateUser", paramClass);
	}

	public static void deletUser(String id) throws SQLException {
		SqlMapLocator.getSqlMap().delete("member.deleteUser", id);
	}
	public static void createTable(MemberDto paramClass)throws SQLException{
		SqlMapLocator.getSqlMap().queryForObject("member.createTable", paramClass);
	}

}
